import config from 'config'
import httpFetch from 'share/httpFetch'

export default {

  //获得规则列表
  getRules(expenseTypeOID, setOfBooksId) {
    return httpFetch.get(`${config.baseUrl}/api/travel/standards/rules/information`, {
      expenseTypeOID,
      page: 0,
      size: 1000,
      setOfBooksId
    });
  },

  //删除规则
  deleteRule(ruleOID){
    return httpFetch.delete(`${config.baseUrl}/api/travel/standards/rules/information/${ruleOID}`)
  },

  //获得条件列表
  getConditions(ruleOID){
    return httpFetch.get(`${config.baseUrl}/api/travel/standards/rule/conditions`, { ruleOID })
  },

  //的到管控项列表
  getPullData(entityOID, setOfBooksId) {
    return httpFetch.get(`${config.baseUrl}/api/travel/standards/config/pullData`, {
      entityOID,
      setOfBooksId
    });
  },

  getDepartment(isAll) {
    return httpFetch.get(`${config.baseUrl}/api/department/like${isAll ? '?roleType=TENANT' : ''}`,
      {
        flag: 1002,
        hasChildren: false,
        name: ''
      }
    );
  },

  getCostCenterItems(costCenterOID){
    return httpFetch.get(`${config.baseUrl}/api/cost/center/items/${costCenterOID}/all?page=0&size=100`)
  },

  getUserGroup(isAll){
    return httpFetch.get(`${config.baseUrl}/api/user/groups/company${isAll ? '?roleType=TENANT' : ''}`, { page: 0, size: 1000 })
  },

  getCountry(language = 'zh_cn', isAll){
    let params = {
      language,
      type: 'country'
    };
    return httpFetch.get(`${config.baseUrl}/api/areas/international/list${isAll ? '?roleType=TENANT' : ''}`, params);
  },

  getCityGroup(isAll){
    return httpFetch.get(`${config.baseUrl}/api/levels/my${isAll ? '?roleType=TENANT' : ''}`, {
      deleted: false,
      page: 0,
      size: 1000
    })
  },

  getCustomEnumerations(OID){
    return httpFetch.get(`${config.baseUrl}/api/custom/enumerations/${OID}/items/by/user`, { page: 0, size: 1000 })
  },

  /**
   * 保存规则
   * @param condition
   * @return {*|AxiosPromise}
   */
  saveRule(condition){
    return httpFetch.post(`${config.baseUrl}/api/travel/standards/config/rules`, condition)
  },

  saveCondition(ruleOID,  condition){
    return httpFetch.post(`${config.baseUrl}/api/travel/standards/config/condition/${ruleOID}`, condition)
  },

  deleteCondition(id){
    return httpFetch.delete(`${config.baseUrl}/api/travel/standards/config/condition/${id}`)
  },

}
